<%@page import="java.io.PrintWriter"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>my page</title>
<style type="text/css">
*{
margin:0px;
padding:0px;
}
#image1{
      
	  background:url(image/1.jpg);
	  background-position:center;
	  background-size:cover;
	  width:1350px;
	  height:1000px;
	  z-index:-1;
	  background-repeat:no-repeat;
}
.center{/*这是控制中间的部分的样式表*/
     width:920px;
     height:1000px;
     top:10px;
     left:200px;
    
     position:absolute;
}
#image2{ 
		background:url(image/2.jpg);
		width:100%;
		top:50px;left:385px;
		height:356px;
		background-repeat:no-repeat;
		
}
/*下面是关于left部分的布局*/
#display{
top:315px;
width:920px;
height:644px;
background-color:white;
position:absolute;
}

/*下面是底部的布局*/
#bottom{
background:url(image/3.png);
width:1350px;
height:260px;
}
.research{
width:860px;
height:45px;
top:10px;
left:10px;
font-size:30px;
position:relative;
}
.post{
width:860px;
height:150px;
left:30px;
top:30px;
border:1px solid black;
position:relative;
}
ul{list-style:none;
  left:150px;
  top:600px;
  position:absolute;
}
li{
	width:98px;
	height:20px;
	border:1px solid #d00;
	margin-left:5px;
	text-align:center;
	color:#333;
	background-color:#cf3;
	float:left;
}
#tname{

 top:60px;
 position:relative;
}
</style>
</head>
<body>

	<div id="image1">
		<div class="center">
			<div id="image2">
			</div>
			 <div id="display">
			<div class="research">
	         <form method="post" action="/xiaonei1227/research.jsp" AUTOCOMPLETE="OFF">
	         <div style="float:left; font-size:20px; top:10px; position:relative;">
	        	 请选择搜索的方式：
	            <select name="way" style="width:60px; height:30px;">
	            <option value="topic_num">类别</option>
	            <option value="theme" selected="selected">主题</option>
	            </select>
	            &nbsp
	         </div>
	         <input type="text" name="research" size="60" style="height:30px; font-size:60%"/>
	         <button type="submit" style="font-size:20px;">搜索</button>
	         </form>
	         </div>
	       <%
			java.sql.Connection conn = null;
		    String sql=null;
		    java.sql.Statement state=null;
		    ResultSet set=null;
		    int count;
		    int topic_num=0;
		    request.setCharacterEncoding("utf-8");
	    	 String way=request.getParameter("way");
	    	 String research=request.getParameter("research");
	    	 
		    try{
		    	Class.forName("org.gjt.mm.mysql.Driver").newInstance();
		    	conn=java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/school1130", "root", "root");
		    	state = conn.createStatement();
		    	
		    	
		    	 if(way.equals("topic_num")){
		    		  sql="select topic_num from topic where  type like '%"+research+"%'";
		    		  set=state.executeQuery(sql);
		    		  set.next();
		    		  topic_num = set.getInt(1);
		    		  sql ="select count(*) from post where topic_num like '%"+topic_num+"%'";
		    		  set.close();
		    	 }else{
		    		    sql = "select count(*) from post where "+ way+"  like '%"+research+"%'";
		    		  }
		    	
		    	set=state.executeQuery(sql); 
		        set.next();
		    	count=set.getInt(1);
		    	
		    	if(way.equals("topic_num")){
		    		if(count>=3){
		    			sql="select * from post where topic_num like '%"+topic_num+"%' limit 0,3";
		    		}else{
		    			sql ="select * from post where topic_num like '%"+topic_num+"%' limit 0,"+count;
		    		}
				 }else{
					    if(count>=3){
				    	 	sql = "select * from post  where "+ way+" like '%"+research+"%' limit 0,3";
				    	}else{
				    		sql ="select * from post where  "+ way+" like '%"+research+"%' limit 0,"+count;
				    	} 
				 }
		    	
		    	set= state.executeQuery(sql);%>
		    	
		    	<% 
		    	while(set.next()) {
		    		out.print("<div class='post'><a href='tiezi.jsp?post_Num="+set.getInt("post_num")+"'>"+(String)set.getString("theme")+"</a><br/><br/>");
		            out.println((String)set.getString("content")+"<br/><div id='tname'>");
		            out.println((String)set.getString("time")+"&nbsp &nbsp &nbsp &nbsp &nbsp  &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp");
		            out.println((String)set.getString("account")+"</div></div>");
		    	}
		         %>    	
		    	
		    	
					   <%
			 out.print("<ul id='div'>");
			
			for(int i=1;i<=(count+2)/3;i++)
				out.print("<li><a href='/xiaonei1227/research2.jsp?number="+i+"&count="+count+"&way="+way+"&research="+research+"'>"+i+"</a></li>");
			out.print("</ul>");
			%>
			 </div>
</div>
</div>
            <%  }catch(Exception e){
             	e.printStackTrace();
             }finally{
             set.close();
    	     state.close();
    	     conn.close();
             }%>
<div id="bottom"> </div>
</body>
</html>